package com.qf.fmall.index.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.fmall.index.entity.Category;
import com.qf.fmall.index.entity.IndexImg;
import com.qf.fmall.index.entity.Product;
import com.qf.fmall.index.service.ICategoryService;
import com.qf.fmall.index.service.IIndexImgService;
import com.qf.fmall.index.service.IProductService;
import com.qf.fmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author dongjl
 * @since 2024-01-16
 */
@CrossOrigin
@RestController
@RequestMapping("/index")
public class IndexImgController {

    @Autowired
    private IIndexImgService iIndexImgService;

    @Autowired
    private ICategoryService categoryService;


    @Autowired
    private IProductService productService;


    @GetMapping("/category-recommends")
    public ResultVo categoryRecommends(){

        List<Category> data = categoryService.categoryRecommends();

        return new ResultVo(1000, "success", data);
    }

    @RequestMapping(value = "/list-recommends",method = {RequestMethod.GET,RequestMethod.POST})
    public ResultVo listRecommends() {

        List<Product> data = productService.listRecommends();

        return new ResultVo(1000, "success", data);
    }

    @GetMapping("/category-list")
    public ResultVo categoryList() {
//        List<Category> data = categoryService.categoryList();
        List<Category> data = categoryService.categoryListPro();
        return new ResultVo(1000, "success", data);
    }

    @GetMapping("/indeximg")
    public ResultVo indeximg() {
        QueryWrapper<IndexImg> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        queryWrapper.orderByAsc("seq"); // order by seq
        List<IndexImg> data = iIndexImgService.list(queryWrapper);
        return new ResultVo(10000, "success", data);
    }

}
